Skip to content

London | 26-ITP-January | Eugenie Ahangama | Sprint 1 | Data Groups#998

Closed
Eugenie-A wants to merge 15 commits intoCodeYourFuture:mainfrom
Eugenie-A:feature/sprint-1
Closed

London | 26-ITP-January | Eugenie Ahangama | Sprint 1 | Data Groups#998
Eugenie-A wants to merge 15 commits intoCodeYourFuture:mainfrom
Eugenie-A:feature/sprint-1

Conversation

@Eugenie-A
Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

  • Fixed calculateMedian implementation in median.js
  • Implemented dedupe.js and wrote tests in dedupe.test.js
  • Implemented findMax in max.js and wrote tests in max.test.js
  • Implemented sum.js and wrote tests in sum.test.js
  • Refactored includes.js from a for loop to a for...of loop and added comments to both files

Questions

What makes a good test? What makes a bad test?

@Eugenie-A Eugenie-A added 🏕 Priority Mandatory This work is expected 🐂 Size Medium 1-4 hours 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Submit:PR Module-Data-Groups The name of the module. Core This is a core task and should be completed by all trainees labels Mar 11, 2026
Comment thread Sprint-1/fix/median.js Outdated
// Return null if no valid numbers remain
if (nums.length === 0) return null;

const sorted = [...nums].sort((a, b) => a - b);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make a copy of nums before sorting?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used [...nums] because I wanted to avoid mutating the input array list. However, since nums is already created by filter, it's a brand new array and not a reference to list. So sorting nums directly won't affect the original input, making the spread unnecessary. I'll remove it.

Comment thread Sprint-1/implement/dedupe.test.js
Comment thread Sprint-1/implement/max.test.js
Comment thread Sprint-1/implement/sum.test.js
@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 19, 2026
@Eugenie-A Eugenie-A added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 19, 2026
Copy link
Copy Markdown
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other changes are good.

Comment on lines +26 to 33
test("given an array with no duplicates, it returns a copy of the original array", () => {
const input = [1, 2, 3];
const result = dedupe(input);
// Check the contents are the same
expect(result).toEqual(input);
// Check it's a different array, not the same reference
expect(result).not.toBe(input);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your function is correct, but currently there is a chance that an incorrectly implemented function can pass this test. Can you figure out why?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A function that just returns a copy without deduplicating (e.g. return [...arr]) would still pass since [1, 2, 3] has no duplicates.

I've added an extra check using an array with duplicates [1, 1, 2, 3] to make the test more robust.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 19, 2026
@Eugenie-A Eugenie-A added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 19, 2026
Comment thread Sprint-1/implement/dedupe.test.js Outdated
Comment on lines +33 to +34
// Check that a duplicate input is correctly deduped in the result
expect(dedupe([1, 1, 2, 3])).toEqual([1, 2, 3]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case of "array with duplicates" is checked else where.

I was referring to the specific case of "array with no duplicates".
Hint: Is it possible that result and input can have the same wrong content?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, if dedupe mutated input, then toEqual(input) would still pass since both would have the same wrong content. I've fixed it by comparing result against a hardcoded [1, 2, 3] instead.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 19, 2026
@Eugenie-A Eugenie-A added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 19, 2026
@cjyuan
Copy link
Copy Markdown
Contributor

cjyuan commented Mar 19, 2026

All good now. Well done!

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 19, 2026
@illicitonion
Copy link
Copy Markdown
Member

Closing PR because the January ITP run has finished. Feel free to re-open if you're still working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Core This is a core task and should be completed by all trainees Module-Data-Groups The name of the module. 🏕 Priority Mandatory This work is expected 🐂 Size Medium 1-4 hours 📅 Sprint 1 Assigned during Sprint 1 of this module Submit:PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants